package events;

import java.util.ArrayList;

import general.Mechanisme;

public class EventSystem
{
	public ArrayList<Event> histoire = new ArrayList<Event>();
	
	Mechanisme m;
	
	int time = 0;
	
	public EventSystem( Mechanisme m )
	{
		this.m = m;
	}
	
	public void avancer()
	{
		time++;
		
		System.out.println("Time : " + time);
		
		
		ArrayList<Event> finis = new ArrayList<Event>();
		
		for( int i = 0 ; i < histoire.size() ; i++ )
		{
			histoire.get(i).debut--;
			
			if( histoire.get(i).debut <= 0 && -histoire.get(i).debut <= histoire.get(i).duree )
			{
				histoire.get(i).activation( m );
			}
			
			if( -histoire.get(i).debut > histoire.get(i).duree )
			{
				histoire.get(i).finir( m );
				finis.add(histoire.get(i));
			}
		}
		
		histoire.remove(finis);
	}
}
